package top.shiyiri.spring5.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Service;
import top.shiyiri.spring5.dao.UserDao;
import top.shiyiri.spring5.dao.UserDaoImpl;

import javax.annotation.Resource;


/**
 * @author Aunean
 * @date 2022/2/17 16:05
 */
//注解中value属性值可以省略不写，默认值是类名称，首字母小写，userService
//@Service(value = "userService") //类似于：<bean id="userService" class="位置" />
//@Controller
@Component
public class UserService {

    //普通类型属性注入
    @Value("abc")
    private String name;

    //定义dao类型的属性
    //不需要添加set方法，添加注入属性注解
//    @Autowired //根据类型进行注入
//    @Qualifier("userDaoImpl1") //根据名称进行注入，需要和 Autowired 搭配使用
    @Resource(type = UserDao.class) //根据类型注入
//    @Resource(name = "userDaoImpl1") //根据名称注入
    private UserDao userDao;

    public void add() {
        System.out.println("service add...." + name);
        userDao.add();
    }
}
